package com.shj.em.biz.prod.service;

import com.shj.em.biz.sell.entity.Order;
import com.shj.em.biz.sell.mapper.OrderMapper;
import com.shj.em.biz.prod.entity.OrderOutdate;
import com.shj.em.biz.prod.mapper.OrderOutdateMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 出货日期调整信息 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-07-12
 */
@Service
@Transactional
public class OrderOutdateServiceImpl extends ServiceImpl<OrderOutdateMapper, OrderOutdate> implements OrderOutdateService {

    @Autowired
    OrderOutdateMapper orderoutdateMapper;

    @Autowired
    OrderMapper orderMapper;

    public Page<OrderOutdate> queryOrderOutdatePage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<OrderOutdate> page = new Page(pageNo, pageSize);
        List<OrderOutdate> list = orderoutdateMapper.queryOrderOutdatePage(page, params);
        return page.setRecords(list);
    }

    public void changePlanOutDt(OrderOutdate orderOutdate){
        orderoutdateMapper.insert(orderOutdate);
        Order order = orderMapper.selectById(orderOutdate.getOrderId());
        order.setPlanOutDt(orderOutdate.getOutDt());
        order.setVersion(order.getVersion() + 1);
        orderMapper.updateById(order);
    }
}
